package controller;

import java.awt.image.BufferedImage;
import java.util.*;

import utils.Picture;
import model.PicDatabaseModel;

public class PictureControl {
	private static PictureControl instance;
	
	private PicDatabaseModel dmPicture;
	private HashMap<Integer, Vector<Picture>> hmPicture = new HashMap<Integer, Vector<Picture>>();;
	
	
	public static PictureControl getInstance() {
		if(instance == null) {
			instance = new PictureControl();
		}
		
		return instance;
	}
	
	private PictureControl() {
		dmPicture = new PicDatabaseModel();
	}
	
	public boolean InsertNewPicture( String strPicLocation, 
			String strPicPosition,
			java.util.Date picDate,
			BufferedImage image ) {
		
		if( strPicLocation == null )
			return false;
		if( strPicPosition == null )
			return false;
		if( picDate == null )
			return false;
		if( image == null )
			return false;
		
		dmPicture.InsertPicture(strPicLocation, strPicPosition, picDate, image) ;
		
		return true;
	}
	
	public void DeletePicture() {
		
	}
	
	public HashMap<Integer, Vector<Picture>>  SearchDatabaseForPictures( String strPicLocation,
			int[] camIDs,
			Date dateFrom,
			Date dateTo ) {
		
		
		for( int i = 0; i < camIDs.length; i++ ) {
			hmPicture.put(i, new Vector<Picture>(dmPicture.GetPictureFromTo(strPicLocation, Integer.toString(camIDs[i]), dateFrom, dateTo)));
		}
		
		
//		Vector<Picture> picList = new Vector<Picture>(dmPicture.GetPictureFromTo(strPicLocation, strPicPosition, dateFrom, dateTo));
		
		return hmPicture;
	}

}
